<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./layui/css/layui.css">
    <style>
        html,
        body {
            margin: 0;
        }

        #particle-canvas {
            width: 100%;
            height: 100vh;
            background: linear-gradient(to bottom, rgb(10, 10, 50) 0%, rgb(60, 10, 60) 100%);
            vertical-align: middle;
        }

        .container {
            width: 100vw;
            height: 100vh;
            position: absolute;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .login {
            width: 400px;
            height: 220px;
            border: 1px solid #cccccc;
            border-radius: 5px;
            font-family: gjm;
        }

        .title {
            font-size: 20px;
            color: #ffffff;
            margin: 20px auto;
            text-align: center;
        }

        .item {
            padding-left: 20px;
            color: #ffffff;
            height: 32px;
        }

        .label {
            width: 100px;
            text-align: right;
        }

        .txt {
            padding-left: 5px;
            color: #ffffff;
            border: none;
            border-bottom: 1px solid #ffffff;
            background-color: transparent;
            width: 200px;
        }

        .btn {
            width: 100%;
        }

        button {
            color: #ffffff;
            border: none;
            width: 70px;
            height: 30px;
            background-color: rgba(32, 178, 171, 0.7)
        }

        button:hover {
            background-color: rgba(32, 178, 171, 0.8)
        }

        button:active {
            background-color: rgba(32, 178, 171, 0.9)
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="login">
            <h2 class="title">学生管理系统</h2>
            <div class="flex item">
                <div class="label">登录名：</div>
                <div><input id="loginId" class="txt" type="text" placeholder="请输入登录名"></div>
            </div>
            <div class="flex item">
                <div class="label">密码：</div>
                <div><input id="loginPwd" class="txt" type="password" placeholder="请输入密码"></div>
            </div>
            <div class="flex item">
                <div class="label">记住密码：</div>
                <div><input class="ck" type="checkbox"></div>
            </div>
            <div class="flex item">
                <div class="btn flex j-c">
                    <button id="btn_login">登录</button>
                </div>
            </div>
        </div>
    </div>
    <canvas id="particle-canvas" width="979" height="865">
    </canvas>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
    <script src="./layui/layui.js"></script>
    <script src="./js/login.js"></script>
    <script>
        //设置Cookie
        // function setCookie(cname, cvalue, exdays) {
        //     var d = new Date();
        //     d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
        //     var expires = "expires=" + d.toGMTString();
        //     document.cookie = cname + "=" + cvalue + "; " + expires;
        // }
        //获取Cookie
        // function getCookie(cname) {
        //     let res = ""
        //     var ca = document.cookie.split('; ');  
        //     ca.map(r=>{
        //         return r.split('=')
        //     }).forEach(r=>{
        //         if(r[0]===cname) {
        //             res = r[1]
        //         }
        //     })
        //     return res;
        // }

        layui.use('layer', function () {
            var layer = layui.layer;

            //如果cookie中存在登录名，直接显示登录名
            if ($.cookie('loginId')) {
                $('#loginId').val($.cookie('loginId'))
            }
            //如果cookie中存在密码，直接显示密码
            if ($.cookie('loginPwd')) {
                $('#loginPwd').val($.cookie('loginPwd'))
                $('.ck').prop('checked', true)
            }

            //登录按钮点击事件
            $("#btn_login").click(function () {
                let loginId = $("#loginId").val().trim()     //获取登录名
                let loginPwd = $("#loginPwd").val().trim()   //获取密码

                $.get('http://www.bingjs.com:81/Admin/Login', {
                    loginId,
                    loginPwd
                }, res => {
                    if (res.success) {
                        //判断是否需要记住密码
                        if ($('.ck').prop('checked')) {
                            //在cookie中保存密码
                            $.cookie('loginPwd', loginPwd, { expires: 7 })
                        } else {
                            //从cookie中移除密码
                            $.removeCookie('loginPwd')
                        }
                        //在cookie中保存登录名
                        $.cookie('loginId', loginId, { expires: 7 })
                        location.href = "index.html"
                    }else{
                        layer.open({
                        title: '消息'
                        , content: `登录失败！${res.message}！`
                    });
                    }
                })
                if (loginId && loginPwd === '123456') {

                } else {
                    
                }
            })
        });

    </script>
</body>

</html>